// Copyright (c) 2024 CHANGLEI. All rights reserved.

import 'package:charts_grasp/src/chart/chart_segment/chart_segment.dart';
import 'package:charts_grasp/src/chart/chart_series/series.dart';
import 'package:charts_grasp/src/chart/chart_series/xy_data_series.dart';
import 'package:charts_grasp/src/chart/common/cartesian_state_properties.dart';
import 'package:flutter/material.dart';

class SegmentProperties {
  SegmentProperties(this.stateProperties, this.segment);

  Color? color;
  Color? strokeColor;

  double? strokeWidth;

  late XyDataSeries<dynamic, dynamic> series;

  XyDataSeries<dynamic, dynamic>? oldSeries;

  late CartesianSeriesRenderer seriesRenderer;

  CartesianSeriesRenderer? oldSeriesRenderer;

  RRect? segmentRect;

  Paint? defaultFillColor;
  Paint? defaultStrokeColor;

  int? oldSegmentIndex;

  late int seriesIndex;

  CartesianChartPoint<dynamic>? currentPoint;
  CartesianChartPoint<dynamic>? point;
  CartesianChartPoint<dynamic>? oldPoint;
  CartesianChartPoint<dynamic>? nextPoint;

  bool? oldSeriesVisible;

  Rect? oldRegion;

  final CartesianStateProperties stateProperties;

  final ChartSegment segment;

  late Path path;

  Path? strokePath;

  Rect? pathRect;

  late RRect trackBarRect;

  Paint? trackerFillPaint;

  Paint? trackerStrokePaint;

  late double x;
  late double low;
  late double high;

  late double openX;
  late double closeX;

  late double topRectY;
  late double bottomRectY;

  late ChartLocation lowPoint;
  late ChartLocation highPoint;
  late ChartLocation minPoint;
  late ChartLocation maxPoint;

  Color? pointColorMapper;

  late bool isSolid = false;
  late bool isBull = false;

  late RRect trackRect;

  Color? negativePointsColor;
  Color? intermediateSumColor;
  Color? totalSumColor;

  late double x1;
  late double y1;
  late double x2;
  late double y2;
  late double x3;
  late double y3;

  late num midX;
  late num midY;

  late double currentCummulativePos;
  late double nextCummulativePos;

  late double currentCummulativeValue;
  late double nextCummulativeValue;

  Path? borderPath;

  late double openY;
  late double closeY;

  late double min;
  late double max;

  late double lowerX;
  late double upperX;

  Paint getTrackerFillPaint() {
    final dynamic seriesWithTrack = series;
    trackerFillPaint = Paint()
      ..color = seriesWithTrack.trackColor
      ..style = PaintingStyle.fill;
    return trackerFillPaint!;
  }

  Paint getTrackerStrokePaint() {
    final dynamic seriesWithTrack = series;
    trackerStrokePaint = Paint()
      ..color = seriesWithTrack.trackBorderColor
      ..strokeWidth = seriesWithTrack.trackBorderWidth
      ..style = PaintingStyle.stroke;
    seriesWithTrack.trackBorderWidth == 0 ? trackerStrokePaint!.color = Colors.transparent : trackerStrokePaint!.color;
    return trackerStrokePaint!;
  }

  Paint? getConnectorLineStrokePaint() {
    return null;
  }
}
